CFLAGS = -Wall -pedantic -ansi

ALL := advice_server ikkp_server wiki_client
sources := $(wildcard *.c) 

#all
all: $(ALL)
.PHONY: all

# rules
advice_server.out: advice_server.o
	gcc $(CFLAGS) -o $@ $^

ikkp_server: ikkp_server.o bind_to_port.o catch_signal.o error.o handle_shutdown.o \
		open_listener_socket.o read_in.o say.o
	gcc $(CFLAGS) -o $@ $^

wiki_client: wiki_client.o error.o open_socket.o say.o
	gcc $(CFLAGS) -o $@ $^

#.d generation
%.d: %.c
	@set -e; rm -f $@; \
	gcc -MM $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ >$@; \
	rm -f $@.$$$$

# include all the .d files
include $(sources:.c=.d)

# clean action
.PHONY: clean cleanBin cleanObj cleanDep
clean: cleanDep cleanObj cleanBin

cleanDep:
	-rm *.d

cleanObj:
	-rm *.o

cleanBin:
	-rm $(ALL)
# add something to test 
